package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class ItemCon here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ItemCon
{
    private static ItemCon instance;
    private ArrayList<Item> itemCon;
    
    public static ItemCon getInstance()
    {
        if(instance == null)
        {
            instance = new ItemCon();
        }
        return instance;
    }
    
    private ItemCon()
    {
        itemCon = new ArrayList<Item>();
    }
    
    public ArrayList<Item> getItemCon()
    {
        return itemCon;
    }
    
    public Item getItem(int id)
    {
        boolean found = false;
        int i = 0;
        Item tempItem = null;
        while(i < itemCon.size() && !found)
        {
            tempItem = itemCon.get(i);
            if(tempItem.getId() == id)
            {
                found = true;
            }
            else
            {
                tempItem = null;
                i ++;
            }
        }
        return tempItem;
    }
    
    public void printItem(int id)
    {
        if(getItem(id) != null)
        {
            System.out.println("ID: "+getItem(id).getId());
            System.out.println("Description: "+getItem(id).getDescription());
            System.out.println("Status: "+getItem(id).getStatus());
            System.out.println("Storage: "+getItem(id).getStorage());
            System.out.println("Price: "+getItem(id).getPrice()+" kr. \n");
        }
        else
        {
            System.out.println("Matching item not found for id: "+id);
        }
    }
    
    public void printItemList()
    {
        if(!itemCon.isEmpty())
        {
            System.out.println("List of items: \n");
            for(int i = 0; i < itemCon.size(); i++)
            {
                System.out.println("ID: "+itemCon.get(i).getId());
                System.out.println("Description: "+itemCon.get(i).getDescription());
                System.out.println("Status: "+itemCon.get(i).getStatus());
                System.out.println("Storage: "+itemCon.get(i).getStorage());
                System.out.println("Price: "+itemCon.get(i).getPrice()+" kr. \n");
            }
        }
        else
        {
            System.out.println("There are currently no items listed in the system");
        }
    }
    
    public void addItem(Item item)
    {
        itemCon.add(item);
    }
    
    public void removeItem(int id)
    {
        Item tempItem = getItem(id);
        if(tempItem != null)
        {
            itemCon.remove(tempItem);
        }
        else
        {
            System.out.println("Matching item not found for id: "+id);
        }
    }
}
